const pool = require("../db/conn");

exports.selectRightsAll = async function () {
    let sql = "SELECT rs_right.right_path FROM rs_right";
    let conn = await pool.getConnection();
    let [result] = await conn.execute(sql);
    conn.release();
    return result;
}

exports.selectRights = async function (role_id) {
    let sql =   " SELECT "+
                "   rs_right.right_id,  rs_right.right_name,  rs_right.right_path, rs_right.right_icon, rs_role_right.right_function "+
                " FROM "+
                "   rs_role "+
                " LEFT JOIN "+
                "   rs_role_right ON  rs_role.role_id = rs_role_right.role_id "+
                " LEFT JOIN "+
                "   rs_right ON  rs_role_right.right_id = rs_right.right_id "+
                " WHERE "+
                "   rs_role.role_id = ?"+
                " ORDER BY rs_right.right_id ";
    let conn = await pool.getConnection();
    let [result] = await conn.execute(sql,[role_id]);
    conn.release();
    return result;
}